package edu.guet.server.controller;

import edu.guet.server.model.Comment;
import edu.guet.server.model.User;
import edu.guet.server.service.CommentService;
import edu.guet.server.service.UserService;
import edu.guet.server.utils.ResultAPI;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/post/{post_id}")
public class CommentController {
    @Autowired
    CommentService commentService;

    @GetMapping("/comment")//根据评论区id获取评论
    public ResultAPI selectComment(@PathVariable("post_id") int post_id) {
        return commentService.selectComment(post_id);
    }

    @GetMapping("/comment/sort")//根据时间排序评论区
    public ResultAPI sortComment(@PathVariable("post_id") int post_id) {
        return commentService.sortComment(post_id);
    }


    @PostMapping("/comment/add")//发布评论
    public ResultAPI addComment(@RequestBody Comment comment,@PathVariable("post_id") int post_id){
        return commentService.addComment(comment,post_id);
    }

    @PostMapping("/comment/change")//修改评论
    public ResultAPI changeComment(@RequestBody Comment comment,@PathVariable("post_id") int post_id) {
        return commentService.changeComment(comment,post_id);
    }

    @DeleteMapping ("/comment")//删除评论
    public ResultAPI deleteComment(@RequestBody Comment comment) {
        return commentService.deleteComment(comment);
    }
}
